//
// Created by tang on 23-4-23.
//

#include "class.hpp"
#include "parser/utils.hpp"

Class::Class (const Cursor &cursor, const Namespace &current_ns) :
    TypeInfo (cursor, current_ns), name_ (cursor.display_name ()),
    qualified_name_ (getTypeNameWithoutNamespace (cursor.type ())),
    display_name_(getNameWithoutFirstM (qualified_name_))
{
    replaceAll (name_, " ", "");

    for (auto &child: cursor.children ()) {
        switch (child.kind ())
        {
        case CXCursor_CXXBaseSpecifier: {
            auto base = new BaseClass(child);
            base_classes_.emplace_back (base);
            break ;
        }
        case CXCursor_FieldDecl:{
            fields_.emplace_back (new Field(child, current_ns, this));
            break ;
        }
        case CXCursor_CXXMethod:{
            methods_.emplace_back (new Method(child, current_ns, this));
            break ;
        }
        default: break;
        }
    }
}

std::string Class::full_qualified_name () const
{
    return qualified_name_;
}

BaseClass::BaseClass (const Cursor &cursor): name(getTypeNameWithoutNamespace (cursor.type())) {

}

std::string Class::name ()
{
    return name_;
}
bool Class::should_compile () const
{
    return should_compile_field() || should_compile_method();
}
bool Class::should_compile_field () const
{
    return meta_.flag (All) || meta_.flag (Fields) || meta_.flag (WhiteListFields);
}
bool Class::should_compile_method () const
{
    return meta_.flag (All) || meta_.flag (Methods) || meta_.flag (WhiteListMethods);
}
bool Class::accessible () const
{
    return true;
}
